package com.joylight.controller.content;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.joylight.dto.AdDto;
import com.joylight.service.AdService;

@Controller
@RequestMapping("/ad")
public class AdController {
	
	@Autowired
	private AdService adService;
	
	@RequestMapping("/add")
	@ResponseBody
	public Object add(AdDto adDto) {
		Map<String,Object> map = new HashMap<String,Object>();
		if (adService.add(adDto)) {
			map.put("status", 1);
		}else {
			map.put("status", 0);
		}
		return map;
	}
	
	@RequestMapping("/search")
	@ResponseBody
	public Object search(AdDto adDto) {
		return adService.getByPage(adDto);
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public Object delete(AdDto adDto) {
		Map<String,Object> map = new HashMap<String,Object>();
		if(adService.delete(adDto)) {
			map.put("status", 1);
		}else {
			map.put("status", 0);
		}
		return map;
	}
}
